package org.ninekone.testGame;

public class Background {
	private String imageFileName;
	private float width;
	private float depth;
	public static final float P1_START_X_POS=12.0f;
	public static final float P1_START_Z_POS=0.0f;
	public static final float P2_START_X_POS=-12.0f;
	public static final float P2_START_Z_POS=0.0f;
	private Position p1InitialPosition=new Position(P1_START_X_POS, 0.0f, P1_START_Z_POS);
	private Position p2InitialPosition=new Position(P2_START_X_POS, 0.0f, P2_START_Z_POS);
	private Position p1CurrentPosition;
	private Position p2CurrentPosition;
	private float playerXMinPos;
	private float playerXMaxPos;
	private float playerZMinPos;
	private float playerZMaxPos;
	//public static final float ORIGIN_X_POS=0.0f;
	//public static final float ORIGIN_Z_POS=0.0f;
	
	public Background(String imageFileName, float width, float depth){
		setImageFileName(imageFileName);
		setWidth(width);
		setDepth(depth);
		setBounds();
		p1CurrentPosition=new Position(P1_START_X_POS, 0.0f, P1_START_Z_POS);
		p2CurrentPosition=new Position(P2_START_X_POS, 0.0f, P2_START_Z_POS);
	}
	
	public Background(){
		setImageFileName("heaven.jpg"); //sfondo celeste chiaro tra le nuvole, di default 
		setWidth(100.00f);
		setDepth(100.00f);
		setBounds();
		p1CurrentPosition=new Position(P1_START_X_POS, 0.0f, P1_START_Z_POS);
		p2CurrentPosition=new Position(P2_START_X_POS, 0.0f, P2_START_Z_POS);
	}

	public String getImageFileName() {
		return imageFileName;
	}

	public void setImageFileName(String imageFileName) {
		this.imageFileName = imageFileName;
	}

	public float getWidth() {
		return width;
	}

	public void setWidth(float width) {
		this.width = width;
	}

	public float getDepth() {
		return depth;
	}

	public void setDepth(float depth) {
		this.depth = depth;
	}
	
	public void drawBackground(){
		//metodo richiamato all'interno del runtime, si dovrebbe occupare di ridisegnare il fondale a ogni frame.
	}
	
	public Position getP1CurrentPosition(){
		return p1CurrentPosition;
	}
	
	public Position getP2CurrentPosition(){
		return p2CurrentPosition;
	}
	
	public void resetPositions(){
		p1CurrentPosition.set3DPosition(P1_START_X_POS, 0.0f, P1_START_Z_POS);
		p2CurrentPosition.set3DPosition(P2_START_X_POS, 0.0f, P2_START_Z_POS);
	}
	
	public void resetP1Position(){
		p1CurrentPosition.set3DPosition(P1_START_X_POS, 0.0f, P1_START_Z_POS);
	}
	
	public void resetP2Position(){
		p2CurrentPosition.set3DPosition(P2_START_X_POS, 0.0f, P2_START_Z_POS);
	}
	
	public Position getP1StartPosition(){
		return p1InitialPosition;
	}
	
	public Position getP2StartPosition(){
		return p2InitialPosition;
	}

	public boolean setP1CurrentPosition(Position p1){
		if ((playerXMinPos <= p1.getXPosition() && p1.getXPosition() <= playerXMaxPos)
				&& (playerZMinPos <= p1.getZPosition() && p1.getZPosition() <= playerZMaxPos) ){
			p1CurrentPosition=p1;
			return true;
		}else{
			return false;
		}
	}
	
	public boolean setP2CurrentPosition(Position p2){
		if ((playerXMinPos <= p2.getXPosition() && p2.getXPosition() <= playerXMaxPos)
				&& (playerZMinPos <= p2.getZPosition() && p2.getZPosition() <= playerZMaxPos) ){
			p2CurrentPosition=p2;
			return true;
		}else{
			return false;
		}
		
	}
	
	private void setBounds(){
		playerXMinPos= -width/2;
		playerXMaxPos= width/2;
		playerZMinPos= -depth/2;
		playerZMaxPos= depth/2;
	}

}
